package day3;

/**
 * ClassName：TestTicked
 *
 * @Author：小鱼
 * @Create：2025-08-20 9:54
 */
public class Ticked implements Runnable{
    //总票数
    private int num = 50;
    //使用同步代码块、
    //创建一个锁对象
    Object mutex = new Object();
    @Override
    public void run() {
        synchronized (mutex){
        while (true) {
            if (num <= 0) {
                break;
            }
            try {
                //每隔50ms卖一张
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            String name = Thread.currentThread().getName();
            System.out.println("售票口：" + name + "正在售票" + num);
            num--;
        }
        }
    }
}
